package com.atguigu.eduService.api;

import com.atguigu.commonutils.R;
import com.atguigu.eduService.entity.EduCourse;
import com.atguigu.eduService.entity.EduTeacher;
import com.atguigu.eduService.service.EduCourseService;
import com.atguigu.eduService.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "前台讲师展示")
@RestController
@RequestMapping("/eduService/teacherapi")
@CrossOrigin
public class TeacherApiController {
@Autowired
    private EduTeacherService eduTeacherService;
@Autowired
private EduCourseService eduCourseService;
    @ApiOperation(value = "分页查询讲师列表")
    @GetMapping("getTeacherApiPage/{current}/{limit}")
    public R getTeacherPage(@PathVariable Long current,
                            @PathVariable Long limit){
        Page<EduTeacher> page=new Page<>(current,limit);
        Map<String,Object> map = eduTeacherService.getTeacherApiPage(page);
        return  R.ok().data(map);
    }
    @ApiOperation(value = "分页查询讲师详情")
    @GetMapping("getTeacherCourseById/{id}")
    public R getTeacherCourseById(@PathVariable String id ){
        EduTeacher teacherDetails = eduTeacherService.getById(id);
        QueryWrapper<EduCourse> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("teacher_id",id);
        List<EduCourse> eduCourses = eduCourseService.list(queryWrapper);
        return R.ok().data("details",teacherDetails).data("eduCourse",eduCourses);
    }

}
